package com.itheima.health.controller.admin;

import com.itheima.health.annotation.MyAnno;
import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.service.ReportService;
import com.itheima.health.vo.MemberReport;
import com.itheima.health.vo.OperationsReportVo;
import com.itheima.health.vo.SetmealReport;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/report")
@Slf4j
public class ReportController {

    @Autowired
    private ReportService reportService;

    /**
     * 运营数据导出
     * @param response
     * @throws Exception
     */
    @GetMapping("/exportBusinessReport")
    @MyAnno(empower = "EXPORTBUSINESSREPORT")
    public void exportBusinessReport(HttpServletResponse response) throws Exception {
        reportService.exportBusinessReport(response);
    }

    /**
     * 会员统计
     * @return
     */
    @GetMapping("/getMemberReport")
    @MyAnno(empower = "GETMEMBERREPORT")
    public Result getMemberReport(){
        log.info("[会员统计]");
        MemberReport memberReport = reportService.getMemberReport();
        return new Result(true, MessageConst.GET_BUSINESS_REPORT_SUCCESS,memberReport);
    }

    /**
     * 套餐预约占比
     * @return
     */
    @GetMapping("/getSetmealReport")
    @MyAnno(empower = "GETSETMEALREPORT")
    public Result getSetmealReport(){
        log.info("[套餐预约占比]");
        SetmealReport setmealReport = reportService.getSetmealReport();
        Result result = new Result(true, MessageConst.QUERY_SETMEALLIST_SUCCESS, setmealReport);
        return result;
    }
    /**
     * 15_统计分析-运营统计
     * @return
     */
    @GetMapping("/getBusinessReportData")
    @MyAnno(empower = "GETBUSINESSREPORTDATA")
    public Result getBusinessReportData(){
        try{
            OperationsReportVo operationsReportVo= reportService.getBusinessReportData();
            return new Result(true, MessageConst.GET_BUSINESS_REPORT_FAIL,operationsReportVo);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConst.GET_BUSINESS_REPORT_FAIL);
        }
    }
}
